package com.ftg.learn.chapter10.base02.mapper.sql;

import com.mysql.cj.x.protobuf.MysqlxCrud;
import net.sf.jsqlparser.statement.select.Select;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author 布衣
 */
public class CreateSql {

    public String countSql(@Param("tname") String tname){
        String sql = "select count(teacher_id) from teachers where true ";
        if (tname != null && !tname.isEmpty()) {
            sql += " and teacher_name like concat(#{tname},'%')";
        }
        return sql;
    }

    public String listSql(@Param("tname") String tname,@Param("pageNo") Integer pageNo,@Param("pageSize") Integer pageSize) {
        String sql = "select teacher_id teacherId, teacher_name teacherName, department from teachers where true ";
        if (tname != null && !tname.isEmpty()) {
            sql += " and teacher_name like concat(#{tname},'%')";
        }
        pageNo = (pageNo - 1) * pageSize;
        sql += " limit "+pageNo+",#{pageSize}";
        return sql;
    }

}
